<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <input type="button" value="显示效果" id="btn" />
    <script>
      document.getElementById("btn").onclick = function() {
        alert(12.222);
      };
    </script>

    <input type="button" value="最终版" id="btn1" />
    <!-- 先有按钮，才能获取没获取之后才能注册事件 -->
    <script>
      document.getElementById("btn1").onclick = function() {
        alert("haha");
      }
    </script>
  </body>
</html>
